package com.gitee.theskyzero.data.elasticsearch;

import com.sun.istack.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/data/elasticsearch")
public class ElasticsearchRestController {

    @Autowired
    ElasticsearchRestTemplate template;

    @Autowired
    ElasticRepository repository;

    @GetMapping("/id")
    public ElasticTest findById(@PathVariable String id) {
        ElasticTest elasticTest = template.get(id, ElasticTest.class);
        Optional<ElasticTest> byId = repository.findById(id);
        return byId.orElse(elasticTest);
    }
}
